<?php
/**
 * Created by PhpStorm.
 * User: wangan
 * Date: 2016/11/22
 * Time: 22:06
 */

namespace App\Http\Service;


use App\Models\GroupAnnouncement;

class GroupAnnouncementService
{
    public static function getAnnouncementListPageinit($pageSize=DEFAULT_PAGESIZE,$where=[],$searchVal=null){
        $announceEntity=GroupAnnouncement::where($where)
            ->orderby('sort','DESC')
            ->orderby('id','DESC');
        if(!empty($searchVal)){
            return $announceEntity->where('name','like','%'.$searchVal.'%')
                ->paginate($pageSize);
        }
        return $announceEntity->paginate($pageSize);
    }

    public static function getSourceList(){
        return GroupAnnouncement::getSourceList();
    }

    public static function getTypeList(){
        return GroupAnnouncement::getTypeList();
    }

    public static function createOneAnnounce($announceData){
        return GroupAnnouncement::create($announceData);
    }

    public static function getOneAnnounce($annouceId){
        return GroupAnnouncement::find($annouceId);
    }

    public static function updateOneAnnounce($announceData){
        return GroupAnnouncement::find($announceData['id'])
            ->update($announceData);
    }

    public static function deleteOneAnnounce($annouceId){
        return GroupAnnouncement::find($annouceId)
                    ->update(['isdelete'=>1]);
    }
}